package com.finer.service.impl;

import com.finer.entity.document.FinerGoods;
import com.finer.dao.FinerGoodsDao;
import com.finer.service.FinerGoodsService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 商品表(FinerGoods)表服务实现类
 *
 * @author makejava
 * @since 2024-10-21 10:20:37
 */
@Service("finerGoodsService")
public class FinerGoodsServiceImpl implements FinerGoodsService {
    @Resource
    private FinerGoodsDao finerGoodsDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public FinerGoods queryById(Integer id) {
        return this.finerGoodsDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param finerGoods 筛选条件
     * @param pageRequest      分页对象
     * @return 查询结果
     */
    @Override
    public Page<FinerGoods> queryByPage(FinerGoods finerGoods, PageRequest pageRequest) {
        long total = this.finerGoodsDao.count(finerGoods);
        return new PageImpl<>(this.finerGoodsDao.queryAllByLimit(finerGoods, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param finerGoods 实例对象
     * @return 实例对象
     */
    @Override
    public FinerGoods insert(FinerGoods finerGoods) {
        this.finerGoodsDao.insert(finerGoods);
        return finerGoods;
    }

    /**
     * 修改数据
     *
     * @param finerGoods 实例对象
     * @return 实例对象
     */
    @Override
    public FinerGoods update(FinerGoods finerGoods) {
        this.finerGoodsDao.update(finerGoods);
        return this.queryById(finerGoods.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.finerGoodsDao.deleteById(id) > 0;
    }
}
